{% extends "base.html" %}
{% block title %}{% endblock %}
{% block content %}
<br>

<form class="layui-form" action="" id="cross_srh">
    <div class="layui-input-inline">
        <label class="layui-form-label">项目*：</label>
        <div class="layui-input-inline">
            <select class="layui-select" name="project_name" id="project_name" lay-verify="" lay-search
                    lay-filter="project_name">
                <option value="">请选择</option>
                {% for d in projectAll %}
                <option value="{{d.id}}">{{d.project_name}}</option>
                {% endfor %}
            </select>
        </div>
    </div>
    <div class="layui-input-inline" id="project_version_div">
        <label class="layui-form-label">执行任务：</label>
        <div class="layui-input-inline">
            <div id="project_version" style="width: 212px"></div>
        </div>
    </div>

    <div class="layui-input-inline">
        <label class="layui-form-label">结果：</label>
        <div class="layui-input-inline">
            <div id="case_result" style="width: 212px"></div>
        </div>
    </div>
<br><br>
    <div class="layui-input-inline">
        <label class="layui-form-label">关键字：</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="key_words" id="key_words" placeholder="请输入"
                   style="width: 298%">
        </div>
    </div>

    <div class="layui-input-inline" style="float:right;float:2px">
        <button class="layui-btn  layui-btn-danger" type="button" id="start" lay-submit
                lay-filter="start">查询
        </button>

    </div>

</form>

<hr class="layui-bg-gray">

<table class="layui-hide" id="hisResult" lay-filter="hisResult"></table>

<script>
    layui.use(['table','element','xmSelect'], function(){
          var table = layui.table
          ,form = layui.form;
          var $= layui.jquery;
          var xmSelect = layui.xmSelect;
          var element = layui.element;
          var resultSelect = xmSelect.render({
              el: '#case_result',
              name:"result",
              data: [{"name":"PASS","value":"PASS"}
                    ,{"name":"FAIL","value":"FAIL"}
                    ,{"name":"BLOCK","value":"BLOCK"}
                    ,{"name":"NT","value":"NT"}
              ]
          });
          $("#project_version_div").hide();

          var  options = {
                elem:'#hisResult',
                skin:"line",
                page:true,
                height: 'full-200',
                toolbar: true,
                limit:100,
                limits:[100,500,1000],
                response:{
                    statusName:'errorCode',
                    statusCode:'',
                    dataName:'data'
                },
                id:"hisResult",
                cols:[[
                       {type: 'numbers',title:'No.'},
                      ,{field: 'case_no', title: '用例编号',hide:true,sort:true}
                      ,{field: 'case_require_no', title: '需求编号',sort:true,hide:true}
                      ,{field: 'case_main_mod', title: '主模块',width:100,sort:true}
                      ,{field: 'case_second_mod',hide:true, title: '子模块',sort:true}
                      ,{field: 'case_pri', title: '级别',sort:true,hide:true}
                      ,{field: 'case_pre', title: '前提',sort:true,event:'t4'}
                      ,{field: 'case_title', title: '*标题*',sort:true,event:'t1'}
                      ,{field: 'case_step', title: '步骤',sort:true,event:'t2'}
                      ,{field: 'case_expect', title: '期待结果',sort:true,event:'t3'}
                      ,{field: 'case_note', title: '备注',hide:true,sort:true}
                      ,{field: 'up_person', title: '用例创建人',sort:true,hide:true,templet: function(d){
                            return d.up_person_name;

                      }}
                      ,{field: 'result', width:110,title: '测试结果',sort:true}
                      ,{field: 'bug_url', title: '地址',sort:true}
                      ,{field: 'bug_des', title: '描述',sort:true}
                      ,{field: 'update_time', title: '用例时间',sort:true,hide:true}
                      ,{field: 'id', title: '用例Id',sort:true,hide:true}
                      ,{field: 'person', title: '测试人',hide:true,sort:true}
                      ,{field: 'result_id', title: '结果Id',sort:true,hide:true}
                      ,{field: 'imag_desc', title: '图片',sort:true,hide:true}

                     ]]
                ,data:[]
                ,done:function(res,cur,count){
                    layui.each(res.data,function(index,item){

                         if(item.result == "PASS"){
                            $("tr[data-index='"+index+"']>td[data-field='result']").css('background','lightgreen');
                         }else if(item.result == "FAIL"){
                            $("tr[data-index='"+index+"']>td[data-field='result']").css('background','orangered');
                         }else if(item.result == "BLOCK"){
                            $("tr[data-index='"+index+"']>td[data-field='result']").css('background','yellow');
                         }
                    });

                    form.render();

                }
          }
          var tableIns = table.render(options);

          form.on('submit(start)', function(obj){

                if(obj.field.project_name == "" ){
                    layer.msg("项目不能为空!");
                    return false;
                }
                var loading = layer.load();

                  options = {
                    elem:'#hisResult',
                    skin:"line",
                    page:true,
                    url:'/basecase/case/hisResult/search?',
                    height: 'full-200',
                    toolbar: true,
                    limit:100,
                    limits:[100,500,1000],
                    where:{
                        project_version : obj.field.project_version,
                        project_id : $('#project_name option:selected').val(),
                        result: obj.field.result,
                        key_words: $('#key_words').val(),
                    }
                  }
                  tableIns.reload(options);
                  layer.close(loading);

          });


          //根据项目，在结果表中查询所有的执行任务
          form.on('select(project_name)', function(obj){
                $("#project_version_div").show();
                $.ajax({
                   //发出请求
                   type:"GET",
                   url:"/basecase/case/result/allDoVersion?",
                   contentType: 'application/json; charset=utf-8',
                   dataType:"json",
                   data:{"project_id":obj.value},
                   success: function(result){
                        var casePlanArray = new Array();
                        layui.each(result.data,function(k,v){
                            casePlanArray.push({"name":v.project_version,"value":v.project_version});

                        });
                        var case_module = xmSelect.render({
                              el: '#project_version',
                              name:'project_version',
                              data: casePlanArray
                        });
                        form.render();
                   }
                });

          });

          form.render();
    });
</script>
{% endblock %}